import dayjs from "dayjs";

export function calculateRelativeTime(publishDate: Date): string {
	const now = dayjs();
	const published = dayjs(publishDate);
	const duration = now.diff(published, "hour");
	if (duration < 1) return published.format("HH:mm");
	else if (duration < 24) return `${duration}小时前`;
	else if (duration < 48) return `昨日 ${published.format("HH:mm")}`;
	else
		return published.format(
			published.year() === now.year() ? "MM-DD HH:mm" : "YYYY-MM-DD HH:mm"
		);
}
